import Vue from 'vue'
import App from './App.vue'
import router from './router'
import Vant from 'vant';
import { Stepper } from 'vant';
import { Toast } from 'vant';

import 'vant/lib/index.css';
import "./assets/css/public.css"
import "./assets/css/login.css"
import "./assets/css/login_two.css"
import "./assets/css/configuration.css"
import "./assets/css/iconfont.css"


import ElementUI from 'element-ui';             //全局引入element
import 'element-ui/lib/theme-chalk/index.css';    //全局引入element的样式


Vue.use(Vant);
Vue.use(ElementUI);     //全局注入element



Vue.use(Stepper);

Vue.use(Toast);

Vue.config.productionTip = false
//导入axios
import axios from "axios";

//设置axios得请求拦截器---在请求头上添加token
axios.interceptors.request.use(config=>{
  //从sessionStorage获取token值
  var token = sessionStorage.getItem("token");
  if(token){ //token不为空则为真
    //请求头中会携带token
    config.headers.token=token;
  }
  return config;
})

//前置守卫
router.beforeEach((to,from,next)=>{
  //获取跳转的路径
  var path = to.path;
  if (path==="/login"){
    return next();
  }
  if (path==="/login_two"){
    return next();
  }
  if (path==="/collect"){
    return next();
  }
  if (path==="/open"){
    return next();
  }
  if (path==="/reg"){
    return next();
  }
  var token = sessionStorage.getItem("token");
  if (token){
    return next();
  }
  return next("/login");
})

//把axios挂载到vue对象中,以后在vue中如果使用axios直接可以用$http名称
Vue.prototype.$http=axios

//设置axios基础路径
axios.defaults.baseURL="http://192.168.1.37:7000"
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
